<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/1/30
 * Time: 20:50
 */

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;  //软删除

class User extends Model
{
    //protected $table = 'think_user';
    //protected $pk = 'uid';     //主键id
    protected $json = ['info'];     //定义json字段
    protected $autoWriteTimestamp = true;  //自动写入时间戳
    /*软删除*/
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;
    /*软删除*/

    //字段类型转换，设置了该属性后，就可以输出想要的时间戳。该属性的优先级，大于配置datetime_format的优先级
    protected $type = [
        'birthday'  =>  'timestamp:Y-m-d',   //timestamp或者int
    ];

    // 模型初始化
    protected static function init()
    {
        self::beforeInsert(function ($user) {
            if ($user->status != 1) {
                return false;
            }
        });
        //TODO:初始化内容
    }

    /*public function getStatusAttr($value)
    {
        $status = [-1=>'删除',0=>'禁用',1=>'正常',2=>'待审核'];
        return $status[$value];
    }*/

    public function getStatusTextAttr($value,$data)
    {
        $status = [-1=>'删除',0=>'禁用',1=>'正常',2=>'待审核'];
        return $status[$data['status']];
    }


    /****************************************模型关联**************************************************************/
    public function profile()
    {
        return $this->hasOne('Profile');
    }



}